package com.qdxwx.data.service.account;

import com.qdxwx.common.page.PageRequest;
import com.qdxwx.data.mapper.account.UserAccountDetailMapper;
import com.qdxwx.models.account.UserAccountDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * UserAccountDetail接口
 * Qdx NetSchool Platform
 * @author qdxwx
 * @updateTime 2022/5/25
 * @description
 */
@Service
public class UserAccountDetailServiceImpl implements UserAccountDetailService {

 	@Autowired
    private UserAccountDetailMapper userAccountDetailMapper;
    
    /**
     * 添加UserAccountDetail
     * @param userAccountDetail 要添加的UserAccountDetail
     * @return id
     */
	@Override
    public int insert(UserAccountDetail userAccountDetail) {
		userAccountDetail.setCreateTime(LocalDateTime.now());
		return userAccountDetailMapper.insertUserAccountDetail(userAccountDetail);
	}

    /**
     * 根据id获取单个UserAccountDetail对象
     * @param id 要查询的id
     * @return UserAccountDetail
     */
	@Override
    public UserAccountDetail get(Long id){
    	return userAccountDetailMapper.selectById( id);
    }

	@Override
	public UserAccountDetail getByOrderId(int orderId, long userId) {
		return userAccountDetailMapper.getUserAccountDetailByOrderId(orderId, userId);
	}

	/**
     * 根据条件获取UserAccountDetail列表
     * @param userAccountDetail 查询条件
     * @return List<UserAccountDetail>
     */
    public List<UserAccountDetail> getList(UserAccountDetail userAccountDetail, PageRequest pageRequest){
    	return userAccountDetailMapper.selectList(userAccountDetail, pageRequest);
    }

	@Override
	public long count(UserAccountDetail accountHistory) {
		return userAccountDetailMapper.selectCount(accountHistory);
	}

	@Override
	public int updateCombine(long userId1, long userId2) {
    	if(userId1 < 1 || userId2 < 1){
    		throw new RuntimeException("更新账户详情：参数错误");
		}
		return userAccountDetailMapper.updateCombine(userId1, userId2);
	}

}
